package cn.anquing.demo.mybatisplus.util;

import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;

/**
 * <pre>
 *
 * @description
 * @author wangqq
 * @email wangqq65@gdii-yueyun.com
 * @since 2023/10/10 9:44
 * @copyright 广东美云智数科技有限公司
 * </pre>
 */
public class BeanCopyTest {

    public static class Person{
        private String name;

        private Integer age;

        public Person() {
        }

        public Person(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    public static void main(String[] args) {

        Person oldPerson = new Person("wang", 19);
        Person newPerson = new Person("", 19);
        Person newPerson2 = new Person();
        newPerson2.setAge(20);
        BeanUtils.copyProperties(newPerson2,oldPerson);
        // Person{name='null', age=20} 证明是空也会复制
        System.out.println(oldPerson);


    }
}
